#include "SystemSDL_1_2.h"

#include "../../Point.h"
#include "../../Color.h"

#include <SDL.h>

SDL_Surface* CSystemSDL_1_2_Renderer::m_pCurrentContext = NULL;

int CSystemSDL_1_2_Renderer::Init( void )
{
    m_pCurrentContext = SDL_GetVideoSurface();

    if( m_pCurrentContext == NULL )
    {
        printf( "Could not retieve video surface. %s\n", SDL_GetError() );
        return -1;
    }

    return 0;
}

void CSystemSDL_1_2_Renderer::ShutDown( void )
{
    if( m_pCurrentContext != NULL )
        m_pCurrentContext = NULL;
}

int CSystemSDL_1_2_Renderer::DrawPoint( const CPoint& pt, const CColor& color )
{
    unsigned int* pix = SDL_static_cast( unsigned int*, m_pCurrentContext->pixels );
    void* ptr = SDL_static_cast( void*, pix + pt.GetY() * m_pCurrentContext->w + pt.GetX() );

    SDL_memcpy( ptr, &color, sizeof( CColor ) );

    return 0;
}
